package domain.entities;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * Involucrado entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see domain.entities.Involucrado
 * @author MyEclipse Persistence Tools
 */

public class InvolucradoDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(InvolucradoDAO.class);
	// property constants
	public static final String CUIT = "cuit";
    public static final String CNPJ = "cnpj";
    public static final String NIT = "nit";
    public static final String RUT = "rut";
    public static final String DEGREE = "degree";
	public static final String EMAIL = "email";
	public static final String MOBILE_PHONE = "mobilePhone";
	public static final String NOMBRE = "nombre";
	public static final String PHONE = "phone";
	public static final String POSITION = "position";

	protected void initDao() {
		// do nothing
	}

	public void save(Involucrado transientInstance) {
		log.debug("saving Involucrado instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Involucrado persistentInstance) {
		log.debug("deleting Involucrado instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Involucrado findById(java.lang.Integer id) {
		log.debug("getting Involucrado instance with id: " + id);
		try {
			Involucrado instance = (Involucrado) getHibernateTemplate().get(
					"domain.entities.Involucrado", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Involucrado> findByExample(Involucrado instance) {
		log.debug("finding Involucrado instance by example");
		try {
			List<Involucrado> results = (List<Involucrado>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Involucrado instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Involucrado as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Involucrado> findByCuit(Object cuit) {
		return findByProperty(CUIT, cuit);
	}

    public List<Involucrado> findByCnpj(Object cnpj) {
        return findByProperty(CNPJ, cnpj);
    }

    public List<Involucrado> findByNit(Object nit) {
        return findByProperty(NIT, nit);
    }

    public List<Involucrado> findByRut(Object rut) {
        return findByProperty(RUT, rut);
    }

	public List<Involucrado> findByDegree(Object degree) {
		return findByProperty(DEGREE, degree);
	}

	public List<Involucrado> findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List<Involucrado> findByMobilePhone(Object mobilePhone) {
		return findByProperty(MOBILE_PHONE, mobilePhone);
	}

	public List<Involucrado> findByNombre(Object nombre) {
		return findByProperty(NOMBRE, nombre);
	}

	public List<Involucrado> findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List<Involucrado> findByPosition(Object position) {
		return findByProperty(POSITION, position);
	}

	public List findAll() {
		log.debug("finding all Involucrado instances");
		try {
			String queryString = "from Involucrado";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Involucrado merge(Involucrado detachedInstance) {
		log.debug("merging Involucrado instance");
		try {
			Involucrado result = (Involucrado) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Involucrado instance) {
		log.debug("attaching dirty Involucrado instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Involucrado instance) {
		log.debug("attaching clean Involucrado instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static InvolucradoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (InvolucradoDAO) ctx.getBean("InvolucradoDAO");
	}

}